﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Payroll.BusinessLogic;
using Payroll.Common.Utils;
using Payroll.Common.Utils.Html;
using PayrollHR.Web;
using Payroll.BusinessLogic.Audit;
using Payroll.BusinessLogic.Directory;
using Payroll.BusinessLogic.Utils;
using Payroll.BusinessLogic.ExportImport;
using System.IO;

namespace PayrollHR.Administration.Modules
{
    public partial class Logs : BasePayrollAdministrationUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGriv();
            }
        }
        public void BindGriv()
        {
            int year = DateTime.Now.Year;
            int month = DateTime.Now.Month;
            var logs = LogService.GetAllLogs(year, month, 0, int.MaxValue);
            gvLogs.DataSource = logs;
            gvLogs.DataBind();
        }

        protected void btnDeleteLogs_Click(object sender, EventArgs e)
        {
            LogService.ClearLog();
            BindGriv();
        }

        protected void btnDeleteExcel_Click(object sender, EventArgs e)
        {
            string[] filePaths = Directory.GetFiles(Server.MapPath("~/Administration/FileExport/"));
            List<ListItem> files = new List<ListItem>();
            foreach (string filePath in filePaths)
            {
                File.Delete(filePath);
            }
        }

        protected void gvLogs_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvLogs.PageIndex = e.NewPageIndex;
            BindGriv();
        }
    }
}